<?php

/**
 * 用户管理widget
 *
 * @author jiang
 */

namespace Kj\Admin\Html;

use Kj\Admin\Html\Base;

class UserList extends Base
{
    /**
     * 初始化
     *
     * @access public
     */
    public function __construct()
    {
        parent::__construct();
    }
    
    /**
     * 检测是否有权限
     *
     * @access public
     */
    private function checkPermission($module, $class, $function, $data = array())
    {
        $this->hasPermission = $this->acl->checkIfHasPermission($module, $class, $function);
        if(isset($data['id']) && ! $this->acl->checkGroupLevelPermission($data['id'])) $this->hasPermission = false;
    }
    
    /**
     * 用户列表增加操作
     *
     * @access public
     */
    public function add($module, $class, $function)
    {
        $this->hasPermission = $this->acl->checkIfHasPermission($module, $class, $function);
        $html['add'] = $this->hasPermission ?
                    '<li class="right "><a id="submenuaddUser" target="" href="'.U('admin/user/add').'"><i class="icon-plus"></i>&nbsp;添加用户</a></li>'
                        : '';
        return $html['add'];
    }
    
    /**
     * 用户列表编辑操作
     *
     * @access public
     */
    public function edit($module, $class, $function, $data)
    {
        $this->checkPermission($module, $class, $function, $data);
        $html['edit'] = $this->hasPermission ?
                    '<a title="编辑用户" class="btn-icon " target="" href="'.U('admin/user/edit', array('id' => $data['id'])).'"><i class="icon-common-edit icon-pencil"></i></a>'
                        : '<a title="编辑用户" disabled class="btn-icon " target="" href="#"><i class="icon-common-edit icon-pencil disabled"></i></a>';
        return $html['edit'];
    }
    
    /**
     * 用户列表权限操作
     *
     * @access public
     */
    public function acl($module, $class, $function, $data)
    {
        $this->checkPermission($module, $class, $function, $data);
        $html['acl'] = $this->hasPermission ?
                    '<a title="权限维护" class="btn-icon " target="" href="'.U('admin/acl/user', array('id' => $data['id'])).'"><i class="icon-group-managepriv icon-lock"></i></a>'
                        : '<a title="权限维护" disabled class="btn-icon " target="" href="#"><i class="icon-group-managepriv icon-lock disabled"></i></a>';
        return $html['acl'];
    }
    
    /**
     * 用户列表删除
     *
     * @access public
     */
    public function delete($module, $class, $function, $data)
    {
        $this->checkPermission($module, $class, $function, $data);
        $html['delete'] = $this->hasPermission ?
                    '<a class="btn-icon" title="删除用户" target="" href="javascript:ajaxDelete(\''.U('admin/user/delete', array('id' => $data['id'])).'\',\'userList\',confirmDelete)"><i class="icon-remove"></i></a>'
                        : '<a disabled class="btn-icon" title="删除用户" target="" href="#"><i class="icon-remove disabled"></i></a>';
        return $html['delete'];
    }
    
    /**
     * 用户列表批量删除
     *
     * @access public
     */
    public function deleteAll($module, $class, $function, $data)
    {
        $this->checkPermission($module, $class, $function, $data);
        $html['deleteall'] = $this->hasPermission ?
                    '<button class="btn btn-submit btn-default btn-danger" onclick="ajaxDeleteSelect(\''.U('admin/user/delete').'\',\'userList\',confirmDelete, \'ids\')" id="submit" type="submit">批量删除</button>'
                        : '';
        return $html['deleteall'];
    }

}
